package org.runtimedao.dao;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

public class DAOCache {

	private static final Logger LOG = Logger.getLogger(DAOCache.class);

	private static Map<String, Object> daoObjectCache = new HashMap<String, Object>();

	public static synchronized void resetCache() {
		LOG.info("Reseting cache");
		daoObjectCache = new HashMap<String, Object>();
	}

	@SuppressWarnings("unchecked")
	public static synchronized <T> T getFromCache(Class<T> daoClass) {
		return (T) daoObjectCache.get(daoClass.getName());
	}

	public static synchronized <T> void putInCache(T daoObject) {
		LOG.debug("Putting " + daoObject.getClass().getName() + " in cache");
		daoObjectCache.put(daoObject.getClass().getName(), daoObject);
	}

}
